/*
 * 简单的数字加载渐变动画
 * @Author: ljb
 * @Date: 2018-10-26 14:10:49
 * @Last Modified by: ljb
 * @Last Modified time: 2018-11-14 14:59:24
 */
const numberChange = function numberChange(that, key, new_num, old_num = 0, max_count = 60) {
	const different_value = Math.abs(new_num - old_num);

	const change_unit = different_value < max_count ? 1 : parseFloat((different_value / max_count).toFixed(2)); // 设置每次变化的值

	const frame = requestAnimationFrame(() => {
		that[key] += change_unit;
		if (that[key] >= new_num) {
			that[key] = new_num;
			cancelAnimationFrame(frame);
		} else {
			numberChange(that, key, new_num, that[key]);
		}
	});
};

export default numberChange;

